
from .base import Base
from sqlalchemy import Column, ForeignKey, Column, Integer, String, Float, Date, Numeric,JSON, TEXT,SmallInteger
from sqlalchemy.orm import  relationship

class BusinessIntroduction(Base):
    """主营业务"""
    __tablename__ = 'business_introductions'

    id = Column(Integer, primary_key=True)
    company_id = Column(Integer, ForeignKey('companies.id'), nullable=False)
    business_names = Column(JSON)  # 业务名称
    product_names = Column(JSON)  # 产品名称
    business_scope = Column(TEXT)  # 使用Text类型存储经营范围

    company = relationship("Company", back_populates="business_introduction")


class OperationalData(Base):
    """运营业务数据"""
    __tablename__ = 'operational_data'

    id = Column(Integer, primary_key=True)
    company_id = Column(Integer, ForeignKey('companies.id'), nullable=False)
    year = Column(String(255))  # 年份
    cumulative_value = Column(Float)  # 累计值
    end_of_year_value = Column(Float)  # 期末值

    company = relationship("Company", back_populates="operational_data")


class FinancialSummary(Base):
    """
    年度经营评述
    """
    __tablename__ = 'financial_summaries'
    id = Column(Integer, primary_key=True)
    company_id = Column(Integer, ForeignKey('companies.id'), nullable=False)
    report_date = Column(Date)
    summary = Column(TEXT)

    company = relationship("Company", back_populates="financial_summary")


class BusinessComposition(Base):
    """主营构成"""
    __tablename__ = 'business_composition'

    id = Column(Integer, primary_key=True)
    company_id = Column(Integer, ForeignKey('companies.id'), nullable=False)
    report_date = Column(Date)  # 报告日期
    composition_name = Column(String(255))  # 业务名字
    category = Column(SmallInteger) # 0:产品，1:行业，2:地区
    revenue = Column(Numeric(15, 2))  # 营业收入
    cost = Column(Numeric(15, 2))  # 营业成本
    profit = Column(Numeric(15, 2))  # 营业利润
    gross_margin = Column(Numeric(5, 2))  # 毛利率%

    company = relationship("Company", back_populates="business_composition")
